<template>
  <div class="songs-container">
    <div class="tab-bar">
      <span class="item" :class="{ active: id == 0 }" @click="id = 0"
        >全部</span
      >
      <span class="item" :class="{ active: id == 7 }" @click="id = 7"
        >华语</span
      >
      <span class="item" :class="{ active: id == 96 }" @click="id = 96"
        >欧美</span
      >
      <span class="item" :class="{ active: id == 8 }" @click="id = 8"
        >日本</span
      >
      <span class="item" :class="{ active: id == 16 }" @click="id = 16"
        >韩国</span
      >
    </div>
    <!-- 底部的table -->
    <table class="el-table playlit-table">
      <thead>
        <th></th>
        <th></th>
        <th>音乐标题</th>
        <th>歌手</th>
        <th>专辑</th>
        <th>时长</th>
      </thead>
      <tbody>
        <tr
          class="el-table__row"
          v-for="(item, index) in NewSongsLists"
          :key="index"
        >
          <td>{{ index + 1 }}</td>
          <td>
            <div class="img-wrap">
              <img :src="item.album.picUrl" alt="" />
              <span
                class="iconfont icon-play"
                @click="playMusic(item.id)"
              ></span>
            </div>
          </td>
          <td>
            <div class="song-wrap">
              <div class="name-wrap">
                <span>{{ item.name }}</span>
                <span class="iconfont icon-mv" @click="toMV(item.mvid)"></span>
              </div>
              <span>{{ item.alias[0] }}</span>
            </div>
          </td>
          <td>{{ item.artists[0].name }}</td>
          <td>{{ item.album.name }}</td>
          <td>{{ item.duration | timeForm }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //最新音乐列表
      NewSongsLists: [],
      //切换类型对应的id
      id: 0
    };
  },
  created() {
    this.getNewSongs();
  },
  methods: {
    getNewSongs() {
      this.axios
        .get("https://autumnfish.cn/top/song", {
          params: {
            type: this.id
          }
        })
        .then(res => {
          // console.log(res.data.data);
          this.NewSongsLists = res.data.data;
          // console.log(this.NewSongsLists)
        })
        .catch(err => console.log(err));
    },
    playMusic(id) {
      this.axios
        .get("https://autumnfish.cn/song/url?id=" + id)
        .then(res => {
          console.log(res);
          let url = res.data.data[0].url
         this.$parent.url = url
        })
        .catch(err => console.log(err));
    },
    toMV(id){
      // console.log(id)
      this.$router.push('/mv?id='+id)
    }
  },
  watch: {
    id() {
      // console.log(this.id);
      this.getNewSongs();
    }
  }
};
</script>

<style></style>
